#include "StdAfx.h"
#include "ZigZagLineGenerator.h"
#include "SlowMotion.h"
#include <algorithm>

ZigZagLineGenerator::ZigZagLineGenerator(MillingMachine3C * machine):PathLineGenerator(machine)
{
	this->lineEvenCounter = 0;
}

ZigZagLineGenerator::~ZigZagLineGenerator(void)
{
}

void ZigZagLineGenerator::process(MapType *& mt,vector<ConfigurationState*> *& states,const Point3D & pathMiddle,int & instructionNumber)
{
	MapType::iterator innerIt;

	//if(this->lineEvenCounter/2!=0)
	//	std::reverse(mt->begin(),mt->end());

	for(innerIt = mt->begin();innerIt != mt->end();++innerIt)
	{
		MY_DATATYPE x = innerIt->second.x>=pathMiddle.x ? (this->machine->width - innerIt->second.x) : -(pathMiddle.x - innerIt->second.x);
		MY_DATATYPE y = innerIt->second.y>=pathMiddle.y ? (this->machine->height - innerIt->second.y) : -(pathMiddle.y - innerIt->second.y);
		MY_DATATYPE z = innerIt->second.z>=pathMiddle.z ? innerIt->second.z : (pathMiddle.z - innerIt->second.z);
		states->push_back(new SlowMotion(instructionNumber++,x,y,z));
	}
	++this->lineEvenCounter;
}
